﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace proLearningEnglish
{
    public partial class frmWordManager : Form
    {
        //private DataManager objDataManager;

        public frmWordManager()
        {
            InitializeComponent();
        }

        private void frmWordManager_Load(object sender, EventArgs e)
        {
            List<Word> relationlist = frmMain.objDataManager.getWordList();
            lstWord.Tag = relationlist;
            for (int i = 0; i < relationlist.Count; i++)
            {
                int index = lstWord.Items.Add(((Word)relationlist[i]).getLabel());
            }            
        }

        private void lstWord_SelectedIndexChanged(object sender, EventArgs e)
        {
            Word word = ((List<Word>)lstWord.Tag)[lstWord.SelectedIndex];
            List<WordSense> lstWS = frmMain.objDataManager.getAllWordSenseOfWord(word);
            labWord.Text = word.getLabel();
            TreeNode nodeTmp = new TreeNode();
            WordSense ws;
            treWordDetail.Nodes.Clear();
            for (int i = 0; i < lstWS.Count; i++)
            {
                ws = lstWS[i];
                TreeNode nodeType = treWordDetail.Nodes.Add(ws.getTypeString());
                TreeNode nodeSense = nodeType.Nodes.Add("Sense: " + ws.getLabel());
                Word relIsA = frmMain.objDataManager.getWordIsAWord(ws);
                if(relIsA != null)
                {
                    
                    nodeSense.Nodes.Add("Is a: " + relIsA.getLabel());
                }
                List<Word> lstSyn = frmMain.objDataManager.getWordSynonym(word, ws);
                if (lstSyn.Count > 0)
                {
                    TreeNode nodeSyn = nodeSense.Nodes.Add("Synonym");
                    for (i = 0; i < lstSyn.Count; i++)
                    {
                        nodeSyn.Nodes.Add(lstSyn[i].getLabel());
                    }
                }
            }
            treWordDetail.ExpandAll();
        }

        private void btnAddWord_Click(object sender, EventArgs e)
        {
            frmNewWord frm = new frmNewWord();
            frm.Show();
        }

        private void frmWordManager_FormClosing(object sender, FormClosingEventArgs e)
        {
            frmMain.objDataManager.save();
        }
        
    }
}
